#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
#include<queue>
using namespace std;


  struct ListNode {
     int val;
      ListNode *next;
      ListNode() : val(0), next(nullptr) {}
      ListNode(int x) : val(x), next(nullptr) {}
      ListNode(int x, ListNode *next) : val(x), next(next) {}
  };
  class Solution {
  public:

      struct cmp {
          bool operator()(const ListNode* l1, const ListNode* l2)
          {
              return l1->val > l2->val;
          }
      };

      ListNode* mergeKLists(vector<ListNode*>& lists) {
          priority_queue<ListNode*, vector<ListNode*>, cmp> qu;
          for (auto& ch : lists)
          {
              if (ch) qu.push(ch);
          }
          ListNode* hd = new ListNode();
          ListNode* tmp = hd;
          while (qu.size())
          {
              ListNode* cur = qu.top();
              qu.pop();
              if (cur->next) qu.push(cur->next);
              ListNode* Node = new ListNode(cur->val);
              tmp->next = Node;
              tmp = tmp->next;
          }
          tmp = hd->next;
          delete hd;
          return tmp;
      }
  };

int main() {
    return 0;
}